import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store'
import Home from '../views/Home.vue'
import Login from '../views/Login'
import Register from '../views/Register'
import Sport from '../views/Sport'
import Found from '../views/Found'
import Mine from '../views/Mine'
// 引入子级导航
import Zong from '../views/Home/Zong'
import Run from '../views/Home/Run'
import Walk from '../views/Home/Walk'
import Cycling from '../views/Home/Cycling'
import Training from '../views/Sport/Training'
import Coach from '../views/Sport/Coach'
import Course from '../views/Sport/Course'
import Material from '../views/Sport/Material'

//mine中的子级路由
import Settings from '../views/Mine/Settings'
import Person from '../views/Mine/Person'
import  AccountMana from '../views/Mine/AccountMana'
import Find from '../views/Found/Find'
import Dynamic from '../views/Found/Dynamic'
// import Featured from '../views/Found/Featured/Featured'
// import Diet from '../views/Found/Diet/Diet'
// import Shop from '../views/Found/Shop/Shop'

// 引入首页-跑步-跑步设置页面
import Runset from '../views/Home/Run/Runset'
// 引入首页-健走-健走设置页面
import Walkset from '../views/Home/Walk/Walkset'
// 引入首页-骑行-骑行设置页面
import Cyclingset from '../views/Home/Cycling/Cyclingset'
// 引入首页-跑步=跑步记录页面
import Runjilu from '../views/Home/Run/runjilu/runjilu'
// 引入首页-跑步-跑步地图页面
import Runmap from '../views/Home/Run/Runmap'
// 引入首页-健走-健走地图页面
import Walkmap from '../views/Home/Walk/Walkmap'
// 引入首页-骑行-骑行地图页面
import Cyclingmap from '../views/Home/Cycling/Cyclingmap'
import Particular from '../views/Found/particular/particular'
import Release from '../views/Found/Release/Release'
Vue.use(VueRouter)

const routes = [
  // 首页-跑步设置路由
  {
    path: '/runset',
    name: 'runset',
    component: Runset
  },
  // 首页-健走设置路由
  {
    path: '/walkset',
    name: 'walkset',
    component: Walkset
  },
   // 首页-骑行设置路由
   {
    path: '/cyclingset',
    name: 'cyclingset',
    component: Cyclingset
  },
  // 首页-跑步-跑步记录
  {
    path: '/runjilu',
    name: 'runjilu',
    component: Runjilu
  },
  // 首页-跑步-跑步地图
  {
    path:'/runmap',
    name:'runmap',
    component:Runmap
  },
   // 首页-健走-健走地图
   {
    path:'/walkmap',
    name:'walkmap',
    component:Walkmap
  },
  // 首页-骑行-骑行地图
  {
    path:'/cyclingmap',
    name:'cyclingmap',
    component:Cyclingmap
  },
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    redirect: '/home/zong',
    component: Home,
    children: [

      {
        path: 'zong',
        name: 'zong',
        component: Zong
      },
      {
        path: 'walk',
        name: 'walk',
        component: Walk
      },
      {
        path: 'run',
        name: 'run',
        component: Run,
      },
      {
        path: 'cycling',
        name: 'cycling',
        component: Cycling
      },
    ]


  },
  {
    path: '/sport',
    name: 'sport',
    component: Sport,
    redirect: '/sport/training',
    children: [
      // 训练
      {
        path: 'training',
        name: 'training',
        component: Training
      },
      // 教练
      {
        path: 'coach',
        name: 'coach',
        component: Coach
      },
      // 课程
      {
        path: 'course',
        name: 'course',
        component: Course
      },
      // 素材
      {
        path: 'material',
        name: 'material',
        component: Material
      },
    ]

  },
  {
    path: '/found',
    name: 'found',
    component: Found,
    redirect: '/found/find',
    children: [
      //发现
      {
        path: 'find',
        name: 'Find',
        component: Find
       
      },
      //动态
      {
        path: 'dynamic',
        name: 'Dynamic',
        component: Dynamic
      }
    ]
  },
  //动态发布
  {
    path: '/release',
    name: 'Release',
    component: Release
  },
  //动态详情
  {
    path: '/particular/:id',
    name: 'particular',
    component: Particular
  },
  {
    path: '/mine',
    name: 'mine',
    component: Mine
  },
  //设置的路径
  {
    path: '/settings',
    name: 'settings',
    component: Settings,
  },
  //个人信息路由
  {
    path: '/person',
    name: 'person',
    component: Person,
  },
  //账号管理路由
  {
    path: '/accountmana',
    name: 'accountmana',
    component: AccountMana,
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/register',
    name: 'Register',
    component: Register
  }

]

const router = new VueRouter({
  linkActiveClass: 'active',
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  // console.log(to)
  if (to.path == '/register') {
    next();
    return;
  }
  if (to.path == '/login') {
    next()
    return;
  }
  let isLogin = store.state.isLogin;
  if (isLogin) {
    next();
  } else {
    next('/login')
  }

})





export default router
